
package com.kanjian.music.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.kanjian.music.KanjianApplication;
import com.kanjian.music.constants.GenreConstants;

public class Musician implements Serializable {

    private static final long serialVersionUID = 1L;

    @SerializedName("user_pic")
    public String mUserPic;

    @SerializedName("uid")
    public int mUserId;

    @SerializedName("user_name")
    public String mUserName;

    @SerializedName("musician_location")
    public String mUserLocation;

    @SerializedName("is_fan")
    public int mIsFan;

    @SerializedName("new_song")
    public Music mNewSong;

    // 以下为音乐人详情 musician接口所有
    @SerializedName("identity")
    public int[] mIdentity;
    
    @SerializedName("is_fav")
    public int mIsFav; 

    @SerializedName("genre")
    public int[] mGenre;

    @SerializedName("musician_status")
    public String mMusicianStatus;

    @SerializedName("introduction")
    public String mIntroduction;

    @SerializedName("music_list")
    public ArrayList<Music> mMusicList;

    public static ArrayList<Musician> getMusicianListFromJson(String json) {
        if (json != null) {
            try {
                JSONObject jobj = new JSONObject(json);
                if (jobj != null) {
                    return KanjianApplication.GSON.fromJson(jobj.getJSONArray("musician_list")
                            .toString(), new TypeToken<ArrayList<Musician>>() {
                    }.getType());
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }

    public static Musician getMusicianFromJson(String json) {
        if (json != null) {
            return KanjianApplication.GSON.fromJson(json, Musician.class);
        }
        return null;
    }

    public String getGenreString() {
        if (mGenre != null && mGenre.length > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < mGenre.length; i++) {
//                sb.append(GenreConstants.GENRELIST.get(i));
                if (i != mGenre.length - 1) {
                    sb.append("/");
                }
            }
        }
        return "";
    }

}
